package com.jule.miaozhuapc.dao.impl;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import org.springframework.stereotype.Repository;

import com.jule.miaozhuapc.dao.RoomDao;
import com.jule.miaozhuapc.domain.WawaRoom;

@Repository
public class RoomDAOImpl implements RoomDao{
	private EntityManager em;
	@PersistenceContext
	public void setEm(EntityManager em) {
		this.em = em;
	}
	@Override
	public WawaRoom findById(Long id) {
		String hql = "from WawaRoom where id=:id and isDelete = 0";
		WawaRoom wawaRoom = em.find(WawaRoom.class, id);

//				.createQuery(hql, WawaRoom.class)
//				.setParameter("id", id)
//				.getSingleResult();
		return wawaRoom;
	}
	
	/**
	 *  拉取所有游戏房间
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<WawaRoom> findAllRoom() {
		String rql = "from WawaRoom where isDelete = 0 and now() BETWEEN startTime and endTime ORDER BY sort, startTime DESC";
		return em.createQuery(rql).getResultList();
	}

}
